package com.vakitdaraliyor.www.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "Users")
public class User implements Serializable {

	public User() {
		super();
	}

	private static final long serialVersionUID = 5401851789910761674L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;

	@Column(unique=true)
	private String username;
	private String password;
	private String nameSurname;
	private String email;

	@ManyToOne
	private Role role;

	@OneToMany(mappedBy = "user", orphanRemoval = true)
	private List<Countdown> countDownList = new ArrayList<Countdown>();

	// ************ GETTERS - SETTERS ****************** //

	public User(String username, String password, String nameSurname,
			String email, Role role) {
		super();
		this.username = username;
		this.password = password;
		this.nameSurname = nameSurname;
		this.email = email;
		this.role = role;
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNameSurname() {
		return nameSurname;
	}

	public void setNameSurname(String nameSurname) {
		this.nameSurname = nameSurname;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (id != other.id)
			return false;
		return true;
	}

	public List<Countdown> getCountDownList() {
		return countDownList;
	}

	public void setCountDownList(List<Countdown> countDownList) {
		this.countDownList = countDownList;
	}

}
